import type {Reducer, UnknownAction} from '@reduxjs/toolkit'
import {configureStore} from '@reduxjs/toolkit'
import type {UserState} from './modules/users'
import usersReducer from "./modules/users"
import signsReducer from "./modules/signs"
import checksReducer from "./modules/checks"
import newsSlice from "./modules/news"
import {PersistPartial} from 'redux-persist/es/persistReducer'


import {useDispatch} from 'react-redux'


import {persistReducer, persistStore,} from 'redux-persist'
import storage from 'redux-persist/lib/storage'

const persistConfig = {
  key: 'root',
  version: 1,
  storage,
  whitelist: ['token']
}

const store = configureStore({
  reducer: {
    users: persistReducer(persistConfig, usersReducer) as Reducer<UserState & PersistPartial, UnknownAction>,
    signs: signsReducer,
    news: newsSlice,
    checks:checksReducer
  },
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      // serializableCheck: {
      //   ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
      // },
      serializableCheck: false
    }),
})

persistStore(store)

export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch
export const useAppDispatch = useDispatch.withTypes<AppDispatch>() //

// export const useAppDispatch: () => AppDispatch = useDispatch

export default store
